package com.auto.survey.util.monitoring.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.auto.survey.util.monitoring.entity.RearIntersectionVerificationResult

@Dao
interface VerificationResultDao {

    // 插入单个验证结果
    @Insert(onConflict = OnConflictStrategy.Companion.REPLACE)
    suspend fun insert(result: RearIntersectionVerificationResult): Long

    // 插入多个验证结果（返回生成的ID列表）
    @Insert(onConflict = OnConflictStrategy.Companion.REPLACE)
    suspend fun insertAll(results: List<RearIntersectionVerificationResult>): List<Long>

    // 根据计算结果ID查询所有验证结果
    @Query("SELECT * FROM RearIntersectionVerificationResult WHERE calculationResultId = :resultId")
    suspend fun getByResultId(resultId: Long): List<RearIntersectionVerificationResult>

    // 更新验证结果
    @Update
    suspend fun update(result: RearIntersectionVerificationResult): Int

    // 删除验证结果
    @Delete
    suspend fun delete(result: RearIntersectionVerificationResult): Int

    // 删除指定计算结果的所有验证结果
    @Query("DELETE FROM RearIntersectionVerificationResult WHERE calculationResultId = :resultId")
    suspend fun deleteByResultId(resultId: Long): Int
}